package com.zhangmeng.tools.utils;

import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.zhangmeng.tools.builder.MusicPlayerBuilderFactory;
import com.zhangmeng.tools.music.musicPlayer.MusicPlayer;
import javafx.fxml.FXMLLoader;
import javafx.util.BuilderFactory;
import jdk.dynalink.linker.LinkerServices;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : 芊芊墨客
 * @version : 1.0
 * @date : 2023-04-24 14:19
 */
public class FxmlUtils {

    public static void main(String[] args) {
        write_xml();
    }

    public static void read_fxml(){

        try {
            FXMLLoader fxmlLoader = new FXMLLoader();
            URL url = fxmlLoader.getClassLoader().getResource("config/music-list.fxml");
            fxmlLoader.setLocation(url);
            fxmlLoader.setBuilderFactory(new MusicPlayerBuilderFactory());

            ArrayList<MusicPlayer> load = fxmlLoader.load();
            for (MusicPlayer musicPlayer : load) {
                System.out.println(musicPlayer.getFile_path() + " - " + musicPlayer.getFile_lyric());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void write_xml(){
        try {
            FXMLLoader fxmlLoader = new FXMLLoader();
            URL url = fxmlLoader.getClassLoader().getResource("config/music-list.fxml");
            fxmlLoader.setLocation(url);
            fxmlLoader.setBuilderFactory(new MusicPlayerBuilderFactory());

            ArrayList<MusicPlayer> load = fxmlLoader.load();
            
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
